﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Vmago.Models
{
    public class RepositoryShopComment:IShopComment
    {
        #region IShopComment Members

        private ShopCommentDataContext ds;

        public RepositoryShopComment()
        {
            ds = new ShopCommentDataContext();
        }

        public IEnumerable<ShopComment> getShopComment(int shopID)
        {
            IEnumerable<ShopComment> c = null;

            try
            {
                c = from p in ds.ShopComments
                    where p.shopID.Equals(shopID)
                    orderby p.createDate descending
                    select p;
            }
            catch (Exception ex)
            {
                ds.Dispose();
                Console.WriteLine(ex.ToString());
                throw;
            }
            return c;
        }

        public int insertShopComment(int shopID,string subject, string content,string username,string IP,int parentCommentID,int commentType,int imageID,int productID)
        {
            int c=0;
            string type="INS";
 
            try
            {
                c = ds.updateShopComment(type, 0, shopID, subject, content, username, IP, parentCommentID, commentType, imageID, productID);
            }
            catch (Exception ex)
            {
                ds.Dispose();
                Console.WriteLine(ex.ToString());
                
            }
            return c;

             
        }

        public int deleteShopComment(int commentID )
        {
            int c = 0;
            string type = "DEL";
            try
            {
                c = ds.updateShopComment(type, commentID, 0, "0", "0", "0", "0", 0, 0, 0, 0);
            }
            catch (Exception ex)
            {
                ds.Dispose();
                Console.WriteLine(ex.ToString());

            }
            return c;
        }

        public int updateShopComment(int shopID, string subject, string content, string username, string IP, int parentCommentID, int commentType, int imageID, int productID)
        {
            int c = 0;
            string type = "UPD";

            try
            {
                c = ds.updateShopComment(type, 0, shopID, subject, content, username, IP, parentCommentID, commentType, imageID, productID);
            }
            catch (Exception ex)
            {
                ds.Dispose();
                Console.WriteLine(ex.ToString());

            }
            return c;

        }

        #endregion     
    }
}
